/* 
 * @moduleName: TransFormNormalUtil.js
 * @Desc: 普通文本输入框
 * @Author: djkloop 
 * @Date: 2017-11-30 13:48:08 
 * @Last Modified by: djkloop
 * @Last Modified time: 2017-12-12 03:08:17
 */

 import React from 'react'
 import {InputNumber, Input,DatePicker} from 'antd'
 import colUtil from './ColWrapperUtil'
 import moment from 'moment'
 
 export default {
  transformNormal(field,type) {
    let _rules = field.dateRules && type === 'single' ? field.dateRules.rules : [];
    switch (field.dataType) {
      case 'int':
        return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key, {rules:_rules,initialValue: forUpdate ? undefined : field.defaultValue})(
          <InputNumber size="default" max={field.max} min={field.min} placeholder={field.placeholder}/>
        ), field);
      case 'float':
        return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key, {rules:_rules,initialValue: forUpdate ? undefined : field.defaultValue})(
          <InputNumber step={field.step ? field.step : "1"} size="default" max={field.max} min={field.min} placeholder={field.placeholder}/>
        ), field);
      case 'datetime':
      return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key, {rules:_rules,initialValue: forUpdate ? undefined : field.defaultValue ? moment(field.defaultValue) : null})(
        <DatePicker showTime format="YYYY-MM-DD HH:mm:ss" placeholder={field.placeholder || '请选择日期'}/>
      ), field);
      case "primary":
        return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key)(
          <Input type="textarea" autosize={{ minRows: 1, maxRows: 10 }} disabled size="default"/>
        ), field);
      default:
        return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key, {rules:_rules,initialValue: forUpdate ? undefined : field.defaultValue})(
          <Input placeholder={field.placeholder} size="default" addonBefore={field.addonBefore}
                addonAfter={field.addonAfter}/>
        ), field);
    }
  }
 }
